package com.scvtc.service.party.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.scvtc.domain.ResResult;
import com.scvtc.domain.entity.party.PartyDocumention;
import com.scvtc.domain.vo.PageVo;
import com.scvtc.mapper.party.PartyDocumentionMapper;
import com.scvtc.service.party.PartyDocumentionervice;
import com.scvtc.utils.LikeQueryUtil;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

@Service("PartyDocumentionService")
public class PartyDocumentionServiceImpl extends ServiceImpl<PartyDocumentionMapper, PartyDocumention> implements PartyDocumentionervice {
    @Override
    public ResResult<PageVo<List<PartyDocumention>>> getAllInfo(Long current, Long size, PartyDocumention partyDocumention) {

        // 查询学生信息
        Page<PartyDocumention> page = page(new Page<>(current, size),
                LikeQueryUtil.likeQuery(partyDocumention, PartyDocumention.class)
                        .lambda()
        );
        long total = page.getTotal();
        return ResResult.noMsgSuccess(new PageVo<>(page.getRecords(), total));
    }

    @Override
    public ResResult<?> addDocument(PartyDocumention documention) {
        documention.setDocumentionDate(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date()));
        if (save(documention)){
            return ResResult.success(documention.getId());
        }
        // 返回失败
        return ResResult.fail();
    }

    @Override
    public ResResult<?> updateDocument(PartyDocumention documention) {
        if (updateById(documention)){
            return ResResult.success(documention.getId());
        }
        // 返回失败
        return ResResult.fail();
    }

    @Override
    public ResResult<?> deleteDocument(Long id) {
        if (removeById(id)){
            return ResResult.success();
        }
        // 返回失败
        return ResResult.fail();
    }

    @Override
    public ResResult<?> deleteMultipleDelete(Long[] ids) {
        if (removeByIds(Arrays.asList(ids))){
            return ResResult.success();
        }
        // 返回失败
        return ResResult.fail();
    }
}
